package com.sugar.follow.up.module.business.framework.web.convert;

import cn.hutool.core.collection.CollUtil;
import cn.idev.excel.converters.Converter;
import cn.idev.excel.metadata.GlobalConfiguration;
import cn.idev.excel.metadata.data.WriteCellData;
import cn.idev.excel.metadata.property.ExcelContentProperty;
import lombok.extern.slf4j.Slf4j;

import java.io.IOException;
import java.net.URL;
import java.util.List;

/**
 * @author Ysugar
 */
@Slf4j
public class ListToStringConverter implements Converter<List<String>> {

    @Override
    public Class<?> supportJavaTypeKey() {
        return URL.class;
    }

    @Override
    public WriteCellData<?> convertToExcelData(List<String> values, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration)
            throws IOException {

        if (CollUtil.isEmpty(values))
            return new WriteCellData<>("");

        return new WriteCellData<>(String.join(",", values));
    }
}
